package com.zc.springmvc.busniess.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zc.springmvc.busniess.service.Iuser;
import com.zc.springmvc.comresource.IcomStatus;
import com.zc.springmvc.mybatis.bean.UserBean;
import com.zc.springmvc.mybatis.bean.UserLoginFrom;
import com.zc.springmvc.mybatis.mapper.UserBeanMapper;
import com.zc.springmvc.tool.BeanUtil;

@Service
public class UserImpl implements Iuser {
	@Autowired
	private UserBeanMapper umapper;

	public UserBean insertUser(UserBean userbean) throws Exception {

		userbean.setPass(BeanUtil.encryptionBASE64(userbean.getPass()));
		int count = umapper.insert(userbean);
		if (count <= 0) {
			userbean.setStatus(IcomStatus.INSERTFAILED);
		} else {
			userbean.setStatus(IcomStatus.INSERTSUCCESS);
		}
		return userbean;
	}

	public UserBean loginUser(UserLoginFrom userLogin) throws Exception {
		userLogin.setPwd(BeanUtil.encryptionBASE64(userLogin.getPwd()));
		UserBean us = umapper.selectByIdAndPwd(userLogin);
		if (us != null) {
			us.setStatus(IcomStatus.SELECTSUCCESS);
			return us;
		}
		us.setStatus(IcomStatus.SELECTFAILED);
		return us;
	}

	public UserBean deleteUser(UserBean userbean) throws Exception {

		return null;
	}

	public UserBean updateUser(UserBean userbean) throws Exception {
		return null;
	}

}
